/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.answer;

import com.apt.tag.Connect_DB;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.util.Calendar;

/**
 *
 * @author Bach
 */
public class SaverAnswer {
//   
//           (<Request_Text, nvarchar(200),>
//           ,<Request_Sender_Id, int,> cua admin ai gui
//           ,<Request_Time, datetime,>
//           ,<Account_Id, int,>)// cua nguoi dung nguoi nhan

    public static boolean saverAnswer(AnswerForm u) {
        String up = " INSERT INTO [Matrimony].[dbo].[Requests]  ([Request_Text],[Request_Sender_Id],[Request_Time],[Account_Id]) VALUES(?,?,?,?)";
        boolean re = false;
        Connection con = null;
        PreparedStatement ps = null;
//        int accId=u.get

        int accId = 0;
        int userid = 0;
        String text = null;
        Calendar c = Calendar.getInstance();
        long d = c.getTimeInMillis();
        if (u != null) {
            accId = Integer.parseInt(u.getAdminid());
            userid = Integer.parseInt(u.getUserid());
            text = u.getFbanswer();
        } else {
            System.out.println("phan nguoi dung co van de");
            return false;
        }
        try {
            con = Connect_DB.getConnection();
            ps = con.prepareStatement(up);
            ps.setString(1, text);
            ps.setInt(2, userid);
            ps.setDate(3, new Date(d));
            ps.setInt(4, accId);
            int i = ps.executeUpdate();
            if (i > 0) {
                re = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Connect_DB.close(null, null, ps, con);
        }
        return re;
    }
}
